package org.come.Frame;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import javax.swing.BorderFactory;
import javax.swing.JFrame;
import javax.swing.JInternalFrame;
import javax.swing.plaf.basic.BasicInternalFrameUI;

import org.come.Jpanel.RoleToggleJpanel;
import org.come.until.FormsManagement;
import org.come.until.Music;
import org.skill.panel.LxPanel;

import com.tool.tcpimg.UIUtils;
/**
 * 切换属性
 * @author Administrator
 *
 */
public class RoleToggleJframe extends JInternalFrame implements MouseListener {

    private static final long serialVersionUID = -8285327662130024086L;
    private RoleToggleJpanel roleToggleJpanel;
    private int first_x, first_y;// x、y坐标

    public static RoleToggleJframe getRoleToggleJframe() {
        return (RoleToggleJframe) FormsManagement.getInternalForm(123).getFrame();
    }

    public RoleToggleJframe() throws Exception {
    	roleToggleJpanel = new RoleToggleJpanel(this);
        this.getContentPane().add(roleToggleJpanel);

        this.setBorder(BorderFactory.createEmptyBorder());// 去除内部窗体的边框
        ((BasicInternalFrameUI) this.getUI()).setNorthPane(null);// 去除顶部的边框
        this.setBackground(UIUtils.Color_BACK);
        this.setBounds(100, 85, 100, 100);// 设置窗口出现的位置

        this.pack();
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setVisible(false);
        this.addMouseListener(this);
        this.addMouseMotionListener(new MouseMotionListener() {// 判断窗口移动的位置

            @Override
            public void mouseMoved(MouseEvent e) {

            }

            @Override
            public void mouseDragged(MouseEvent e) {
                if (isVisible()) {
                    int x = e.getX() - first_x;
                    int y = e.getY() - first_y;
                    setBounds(x + getX(), y + getY(),getWidth(),getHeight());
                }
            }
        });
    }

    @Override
    public void mouseClicked(MouseEvent e) {

    }

    @Override
    public void mousePressed(MouseEvent e) {
        // 打开了窗体
        if (e.isMetaDown()) {// 检测鼠标右键单击
            FormsManagement.HideForm(123);
            // 开启窗口音效
            Music.addyinxiao("关闭窗口.mp3");
        } else {
            FormsManagement.Switchinglevel(123);
        }
        this.first_x = e.getX();
        this.first_y = e.getY();
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseEntered(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public void mouseExited(MouseEvent e) {
        // TODO Auto-generated method stub

    }

    public RoleToggleJpanel getRoleToggleJpanel() {
        return roleToggleJpanel;
    }

    public void setRoleToggleJpanel(RoleToggleJpanel roleToggleJpanel) {
        this.roleToggleJpanel = roleToggleJpanel;
    }



}
